package dfs_and_bfs


type tLIFOQueue struct {
	nodes []INode
	capacity int
	size int
}

func newLIFOQueue() iNodeQueue {
	it := &tLIFOQueue{}
	it.Clear()
	return it
}

func (me *tLIFOQueue) Clear() {
	me.nodes = make([]INode, 0)
	me.capacity = 0
	me.size = 0
}

func (me *tLIFOQueue) Push(node INode) {
	me.ensureSpace(1)
	me.nodes[me.size] = node
	me.size++
}

func (me *tLIFOQueue) ensureSpace(space int) {
	for me.capacity < me.size + space {
		me.nodes = append(me.nodes, nil)
		me.capacity++
	}
}

func (me *tLIFOQueue) Empty() bool {
	return me.size <= 0
}

func (me *tLIFOQueue) Poll() (bool, INode) {
	if me.Empty() {
		return false, nil
	}

	me.size--
	it := me.nodes[me.size]
	me.nodes[me.size] = nil
	return true, it
}
